package com.shopping.dao;

import com.shopping.pojo.RecMessage;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface RecMessageDao {

    String TABLE_NAME = "rec_message";
    String INSERT_FIELDS = "my_id, user_id, nick_name";
    String SELECT_FIELDS = "id, my_id myId, user_id userId, nick_name nickName";

    @Insert({"insert into ", TABLE_NAME, " (", INSERT_FIELDS, ") values(#{myId}, #{userId}, #{nickName})"})
    int insert(RecMessage recMessage);

    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where user_id=#{userId} and my_id=#{myId}"})
    RecMessage selectByIds(@Param("myId") int myId, @Param("userId") int userId);

    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where my_id=#{myId}"})
    List<RecMessage> selectByMyId(@Param("myId") int myId);

    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where id =#{id}"})
    RecMessage selectById(@Param("id") int id);

    @Delete({"delete from ", TABLE_NAME, " where my_id=#{myId}"})
    int deleteByMyId(@Param("myId") int myId);

    @Delete({"delete from ", TABLE_NAME, " where id=#{id}"})
    int deleteById(@Param("id") int id);

    @Select({"select last_insert_id()"})
    Integer lastInsertId();


}
